<template>
  <el-container>
    <el-header>
      <el-row>
        <el-col :span="16">
          <el-form :inline="true" :model="companyCondition">
            <el-form-item label="企业名称">
              <el-input v-model="companyCondition.condition.name" placeholder="企业名称"/>
            </el-form-item>
            <el-form-item label="业务类型">
              <el-select v-model="companyCondition.condition.businessType" class="company" placeholder="请选择"
                         value-key="name">
                <el-option
                    v-for="(value, key) in businessName"
                    :key="key"
                    :label="value.name"
                    :value="value.name">
                </el-option>
              </el-select>

            </el-form-item>
            <el-form-item label="楼栋号">
              <el-select v-model="companyCondition.condition.buildingIndex" class="company" placeholder="请选择">
                <el-option
                    v-for="(value, key) in builingIndex"
                    :key="key"
                    :label="value"
                    :value="key">
                </el-option>
              </el-select>

            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="pageCompany">查询</el-button>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="8">
          <div style="text-align: right">
            <el-button plain type="success" @click="toChild">查询专利&补贴</el-button>
            <el-button plain type="success" @click="visible.visible = true">添加企业</el-button>
          </div>
        </el-col>
      </el-row>
      <!--      添加企业弹窗-->
      <el-dialog
          :visible.sync="visible.visible"
          title="添加企业"
          width="30%">
        <company-form :businessName="businessName" @success="pageCompany();visible.visible = false;"/>
      </el-dialog>

    </el-header>
    <el-main>
      <el-table
          ref="multipleTable"
          :data="companyData"
          @row-click="clickTr"
      >
        <el-table-column label="企业名称" prop="name"></el-table-column>
        <el-table-column label="企业地址" prop="address"></el-table-column>
        <el-table-column label="企业所在楼栋" prop="buildingIndex"></el-table-column>
        <el-table-column label="企业类型" prop="type"></el-table-column>
        <el-table-column label="认证类型" prop="certificationType"></el-table-column>
        <el-table-column label="业务类型" prop="businessType"></el-table-column>
        <el-table-column label="联系电话" prop="phone"></el-table-column>
        <el-table-column label="联系人" prop="contactPerson"></el-table-column>
        <el-table-column label="员工数量" prop="employeeCount"></el-table-column>
        <el-table-column label="入驻时间" prop="timestamp.timeString"></el-table-column>
      </el-table>
    </el-main>
    <el-footer>
      <el-pagination
          :current-page.sync="companyCondition.page"
          :page-size.sync="companyCondition.size"
          :total="total"
          background
          layout="prev, pager, next,jumper"
          @current-change="pageCompany"
      >
      </el-pagination>
    </el-footer>
  </el-container>
</template>

<script>
import CompanyForm from "./CompanyForm";
import builingIndex from "../../../common/buildingIndex";
import {QueryCompany} from "../../../network/companyApi";
import {findAllBusiness} from "../../../network/businessTypeApi";

export default {
  name: "newCompany",
  components: {
    CompanyForm,
  },
  data() {
    return {
      builingIndex,
      choose: null,
      visible: {
        visible: false,
        editVisble: false,
      },
      selection: {},
      companyCondition: {
        page: 1,
        size: 20,
        condition: {
          name: "",
        },
      },
      companyData: null,
      total: 0,
      businessName: ""
    }
  },
  methods: {

    clickTr(row,) {
      this.$router.push({
        path: '/companyPage',
        query: {
          id: row.uuid,
        }
      })
    },

    pageCompany() {
      QueryCompany(this.companyCondition).then(res => {
        let records = res.data.records
        records.forEach(item => {
          let index = item.buildingIndex
          item.buildingIndex = builingIndex[index]
        })
        this.companyData = records;
        this.total = res.data.total;
      });
    },
    toChild() {
      this.$router.push({
        path: '/hatch/company',
        query: {
          id: this.choose,
        }
      })
    },
  },
  mounted() {
    this.pageCompany()
    findAllBusiness({showMessage: 1}).then(res => {
      this.businessName = res.data
    })

  }
}
</script>

<style scoped>

</style>